import org.grails.plugins.lookups.Lookup
import org.grails.plugins.lookups.LookupValue

class BootStrap {
     
     def authenticateService

     def init = { servletContext ->
        [
        'ROLE_COMPANY_CHIEF':'分公司总经理',
        'ROLE_COMPANY_MANAGER':'分公司总监',
        'ROLE_COMPANY_DIRECTO':'分公司经理',
        'ROLE_SCHOOL_MANAGER':'校区总监', 
        'ROLE_SCHOOL_DIRECTOR':'校区主任', 
        'ROLE_USER':'员工',
        'ROLE_ADMIN':'系统管理员'
        ].each{ entry ->
         new Role(authority:entry.key,
                        description:entry.value).save()
        }

        if (!User.findByUsername('admin')) {
            def person = new User(username: 'admin' , enabled : true , userRealName: "管理员" , mail:"romejiang@gmail.com")
            person.passwd = authenticateService.encodePassword('!Q@W#E$R%T^')
            person.save()
            Role.findByAuthority("ROLE_ADMIN").addToPeople(person) 
        }

         def personalCategory = Lookup.findByRealm('personalCategory') 
        personalCategory = personalCategory?personalCategory:new Lookup(realm:"personalCategory",
                                        codeType:"string",
                                        codeMinimum:"",
                                        codeMaximum:"",
                                        valueType:"string",
                                        valueMinimum:"",
                                        valueMaximum:"",
                                        valueScale:"",
                                        ordering:"sequencer",
                                        internationalize:false,
                                        dateCreated:new Date(),
                                        lastUpdated:new Date() ).save();

         ['最新公告' , '企业文化', '人事档案'].eachWithIndex{it, index ->
         new LookupValue(lookup: personalCategory ,
                                        code: it,
                                        value: it, 
                                        sequencer : index ,
                                        stringSequencer: it,
                                        dateCreated:new Date(),
                                        lastUpdated:new Date()).save()
        }
     }
     def destroy = {
     }
} 